#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 100100
using namespace std;
int p[maxn];
int m[10000010];
int tree[maxn<<2];
int lazy[maxn<<2];
struct node
{
	int l;
	int r;
}a[maxn];
void build(int rt,int s,int e)
{
	if(s==e)
	{
		tree[rt] = 1;
		return ;
	}
	int mid = (s+e) >>1;
	int l_node = rt*2;
	int r_node = rt*2+1;
	build(l_node,s,mid);
	build(r_node,mid+1,e);
	tree[rt] = tree[l_node]+tree[r_node];
}
int query(int rt,int s,int e,int l,int r)
{
	int sum = 0;
	if(l<=s&&e<=r)
	{
		int ans = tree[rt];
		lazy[rt] = 1;
		tree[rt] = 0;
		return ans;
	}
	int mid = (s+e)>>1;
	int l_node = rt*2;
	int r_node = rt*2+1;
	if(lazy[rt])
	{
		lazy[l_node] = lazy[r_node] = 1;
		tree[l_node] = tree[r_node] = 0;
	}
	if(l <= mid) sum += query(l_node,s,mid,l,r);
	if(r > mid) sum += query(r_node,mid+1,e,l,r);
	tree[rt] = tree[l_node]+tree[r_node];
	return sum;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(lazy,0,sizeof(lazy));
		memset(tree,0,sizeof(tree));
		int n,ans;
		ans = 0;
		scanf("%d\n",&n);
		int L,R,k;
		k = 0;
		for(int i = 1;i<=n;i++)
		{
			scanf("%d %d",&L,&R);
			a[i].l=L;
			a[i].r=R;
			p[++k] = L;
			p[++k] = R;
		}
		sort(p+1,p+1+k);
		int cnt = unique(p+1,p+1+k)-(p+1);
		for(int i=1;i<=cnt;i++)
		{
			m[p[i]] = i;
		} 
		for(int i = 1;i<=n;i++)
		{
			a[i].l = m[a[i].l];
			a[i].r = m[a[i].r];
		}
		memset(tree,0,sizeof(0));
		build(1,1,cnt);
		/*for(int i = 1;i<=cnt*2;i++)
		{
			printf("tree[%d]=%d\n",i,tree[i]);
		}*/
		for(int i =n;i>=1;i--)
		{
		/*	printf("i = %d\n",i);
			printf("+++%d %d\n",a[i].l,a[i].r);*/
			int flag = query(1,1,cnt,a[i].l,a[i].r);
			printf("*%d\n",flag);
			if(flag)
			{
				
				//update(1,1,cnt,)
				ans++;
			}
		}   
		printf("%d\n",ans);
	}
} 
